package com.aidex.biz.controller;

import com.aidex.biz.domain.JinjianInfo;
import com.aidex.biz.service.JinjianInfoService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户进件Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/biz/bizJinjianInfo")
public class JinjianInfoController extends BaseController {
    @Autowired
    private JinjianInfoService jinjianInfoService;

    /**
     * 查询客户进件列表
     */
    @GetMapping("/list")
    public R<PageInfo> list(JinjianInfo jinjianInfo, HttpServletRequest request, HttpServletResponse response) {
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianInfo.setCompanyId(null);
        } else {
            jinjianInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        jinjianInfo.setPage(new PageDomain(request, response));
        return R.data(jinjianInfoService.findPage(jinjianInfo));
    }

    @GetMapping("/mylist")
    public R<PageInfo> mylist(JinjianInfo jinjianInfo, HttpServletRequest request, HttpServletResponse response) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianInfo.setUserId(SecurityUtils.getUserId());
        }

        jinjianInfo.setPage(new PageDomain(request, response));
        return R.data(jinjianInfoService.findPage(jinjianInfo));
    }

    /**
     * 客服查询我的签约
     *
     * @param jinjianInfo
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/listBizMyListQianyue")
    public R<PageInfo> listBizMyListQianyue(JinjianInfo jinjianInfo, HttpServletRequest request, HttpServletResponse response) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianInfo.setServcieUserId(SecurityUtils.getUserId());
        }
        jinjianInfo.setPage(new PageDomain(request, response));
        return R.data(jinjianInfoService.findPage(jinjianInfo));
    }

    /**
     * 获取客户进件详细信息
     */
    @GetMapping(value = "/{id}")
    public R<JinjianInfo> detail(@PathVariable("id") String id) {
        return R.data(jinjianInfoService.get(id));
    }

    /**
     * 新增客户进件（方案确认）
     */
    @Log(title = "客户进件", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.add(jinjianInfo));
    }

    /**
     * 修改客户进件
     */
    @Log(title = "客户进件", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.edit(jinjianInfo));
    }


    /**
     * 删除客户进件
     */
    @Log(title = "客户进件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(jinjianInfoService.deleteJinjianInfoByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(jinjianInfoService.findMaxSort(new JinjianInfo()));
    }

    /**
     * 导出客户进件列表
     */
    @Log(title = "客户进件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(JinjianInfo jinjianInfo) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianInfo.setCompanyId(null);
        } else {
            jinjianInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<JinjianInfo> list = jinjianInfoService.findList(jinjianInfo);
        ExcelUtil<JinjianInfo> util = new ExcelUtil<JinjianInfo>(JinjianInfo.class);
        return util.exportExcel(list, "客户进件数据");
    }

    @Log(title = "客服接单", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoKefuConfirm")
    public R updateBizJinjianInfoKefuConfirm(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoKefuConfirm(jinjianInfo));
    }


    @Log(title = "信审确认", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoKefuXinshen")
    public R updateBizJinjianInfoKefuXinshen(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoKefuXinshen(jinjianInfo));
    }

    @Log(title = "进件预审", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoYushen")
    public R updateBizJinjianInfoYushen(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoYushen(jinjianInfo));
    }

    @Log(title = "费用确认", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoConfirmBill")
    public R updateBizJinjianInfoConfirmBill(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoConfirmBill(jinjianInfo));
    }

    @Log(title = "利息确认", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoConfirmInterest")
    public R updateBizJinjianInfoConfirmInterest(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoConfirmInterest(jinjianInfo));
    }

    @Log(title = "重新确认方案", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoConfirmAgain")
    public R updateBizJinjianInfoConfirmAgain(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoConfirmAgain(jinjianInfo));
    }


    @Log(title = "放款", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoFk")
    public R updateBizJinjianInfoFk(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoFk(jinjianInfo));
    }

    @Log(title = "已寄回", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoZiLiaoBack")
    public R updateBizJinjianInfoZiLiaoBack(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoZiLiaoBack(jinjianInfo));
    }

    @Log(title = "进件审核", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoShenHe")
    public R updateBizJinjianInfoShenHe(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoShenHe(jinjianInfo));
    }

    @Log(title = "进件签约", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoQianYue")
    public R updateBizJinjianInfoQianYue(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoQianYue(jinjianInfo));
    }

    @Log(title = "请款确认", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoQingKuan")
    public R updateBizJinjianInfoQingKuan(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoQingKuan(jinjianInfo));
    }


    @Log(title = "回款确认", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoHuiKuan")
    public R updateBizJinjianInfoHuiKuan(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoHuiKuan(jinjianInfo));
    }

    @Log(title = "回款退回", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoHuiKuanRefuse")
    public R updateBizJinjianInfoHuiKuanRefuse(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoHuiKuanRefuse(jinjianInfo));
    }


    @Log(title = "签约驳回", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBizJinjianInfoQianYueRefuse")
    public R updateBizJinjianInfoQianYueRefuse(@RequestBody JinjianInfo jinjianInfo) {
        return R.status(jinjianInfoService.updateBizJinjianInfoQianYueRefuse(jinjianInfo));
    }


}
